var app = getApp(), question = require('../../utils/question.js');
Page({
  data: {
    categoryId: '',
    categoryName: '',
    phoneNo: '',
    passWord: '',
    alertCategory: true,
    checkRadio: '0',
    categoryList : []
  },
  
  onShow:function(){
    var that = this
    var category = wx.getStorageSync('category');
    that.setData({
      categoryId: category.id,
      categoryName: category.name
    })
  },

  goBind: function (e) {
    var that = this;
    console.log("no="+that.data.phoneNo);
    var params = {
      'phoneNo': that.data.phoneNo,
      'signUserid': wx.getStorageSync('uid')
     
    }
    if (params.phoneNo == "" || params.phoneNo == "") {
      wx.showToast({
        title: "请填写手机号",
        icon: 'loading',
        duration: 2e3
      })
      return false;
    }
    
    wx.request({
      url: app.globalData.url + app.interfaceAddress.binding,
      method: 'post',
      dataType: 'json',
      data: params,
      success: function (res) {
        console.log("res.code="+res.data.code);
        if(res.data.code == 0){
          wx.setStorageSync('uid', res.data.data.uid);
          var reCategory = res.data.data.CategoryList;
          console.log("reCategory.size="+reCategory.length);
          if(reCategory.length >0){
            that.setData({
              alertCategory: !that.data.alertCategory,
              categoryList : reCategory,
              radio: reCategory[0].categoryId
            })
          }
        }else{
           wx.showModal({
            title: "手机号码已绑定",
            content: res.data.msg,
            showCancel: !1,
            confirmText: "好的",
            confirmColor: "#1c90fa",
            success: function (e) {
              wx.switchTab({
                url: "../index/index"
              })
            }
          });
        }
        
      }
    })
  },
  goquestion: function (t) {
    wx.navigateTo({
      url: "../errorstar/errorstar?ids="+ t.currentTarget.dataset.ids+"&title=题目详情&navtitle=题目详情&cateName=其他" 
    })
  },

  onChange(event) {
    this.setData({
      radio: event.detail,
    });
  },

  onClick(event) {
    const { name } = event.currentTarget.dataset;
    this.setData({
      checkRadio: name,
    });
  },

  startExam: function (t) {
    console.log("dd="+this.data.checkRadio);
    var uid = wx.getStorageSync('uid');
    if(this.data.radio == ''){
      wx.showModal({
        title: "请选择工种",
        content: res.data.msg,
        showCancel: !1,
        confirmText: "好的",
        confirmColor: "#1c90fa",
        success: function (e) {
          
        }
      });
    }else{
      var detail = this.data.categoryList[parseInt(this.data.checkRadio)];
      
      wx.showLoading({
        title: '加载中',
      })
      var that = this;
      wx.request({
        //url: app.globalData.url + '/routine/auth_api/get_question_list',
        url: app.globalData.url + app.interfaceAddress.questionList,
        method: 'get',
        dataType: 'json',
        data: {
          uid: uid,
          cateid:detail.categoryId
        },
        success:function(res){
          if(res.statusCode == 200){
          
            var q = 'q'+detail.categoryId,qid='qid'+detail.categoryId,qData=res.data.data.question_list,qidData=res.data.data.question_id;
            wx.setStorage({
              key: q,
              data: qData,
              complete: function () {
                wx.setStorage({
                  key: qid,
                  data: qidData,
                  complete:function() {
                    question.initQuestions(q, qid);
                  }
                });
                wx.hideLoading();
                var category = { 'id': detail.categoryId, 'name': detail.categoryName, 'number': parseInt(detail.singleCount) + parseInt(detail.multipleCount) + parseInt(detail.judgeCount), 'time': detail.mnksExamMaxTime, 'passf': detail.mnksExamPassScore,'singleCount': detail.singleCount,'multipleCount':detail.multipleCount,'judgeCount':detail.judgeCount,'singleScore':detail.singleScore,'multipleScore':detail.multipleScore,'judgeScore': detail.judgeScore,'groupQueType':detail.groupQuestionType,'count':detail.counts}
                wx.setStorageSync('category', category)
                
               
               getApp().SyncDataFromDB(uid,detail.categoryId) 
               
                wx.switchTab({
                  url: "../index/index"
                })
              }
            });
          }
        }
      })

     

    }
  },

  
});